package com.example.userwallet.controller;

import com.example.userwallet.pojo.WalletRecord;
import com.example.userwallet.service.UserService;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Author:Nyapii
 */
@RestController
@RequestMapping("/api/v1")
public class WalletController {

    private final UserService userService;

    public WalletController(UserService userService) {
        this.userService = userService;
    }

    /**
     * 查询用户钱包余额
     * @param userId 用户ID
     * @return 用户钱包余额
     */
    @GetMapping("/user/balance")
    public BigDecimal getUserBalance(@RequestParam("userId") Long userId) {
        return userService.getUserBalance(userId);
    }

    /**
     * 用户消费
     * @param userId 用户ID
     * @param amount 消费金额
     * @return 操作是否成功
     */
    @PostMapping("/user/consume")
    public boolean consume(@RequestParam("userId") Long userId, @RequestParam("amount") BigDecimal amount) {
        return userService.consume(userId, amount);
    }

    /**
     * 用户退款
     * @param userId 用户ID
     * @param amount 退款金额
     * @return 操作是否成功
     */
    @PostMapping("/user/refund")
    public boolean refund(@RequestParam("userId") Long userId, @RequestParam("amount") BigDecimal amount) {
        return userService.refund(userId, amount);
    }

    /**
     * 查询用户钱包金额变动明细
     * @param userId 用户ID
     * @return 用户钱包金额变动明细列表
     */
    @GetMapping("/user/wallet_records")
    public List<WalletRecord> getUserWalletRecords(@RequestParam("userId") Long userId) {
        return userService.getUserWalletRecords(userId);
    }

}